package com.xjun.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class RestFulController {
    //原始的传参方式http://localhost:8080/add?a=1&b=2
    @RequestMapping("/add")
    public String add(int a, int b, Model model) {
        int result = a + b;
        model.addAttribute("msg", "结果:" + result);
        return "test";
    }
    //RestFul风格传参http://localhost:8080/add/5/6
//    @RequestMapping("/add/{a}/{b}")
//    public String add2(@PathVariable int a, @PathVariable int b, Model model) {
//        int result = a + b;
//        model.addAttribute("msg", "结果:" + result);
//        return "test";
//    }
    @GetMapping("/add/{a}/{b}")
    public String add3(@PathVariable int a, @PathVariable int b, Model model) {
        int result = a + b;
        model.addAttribute("msg", "结果:" + result);
        //redirect重定向，如redirect:/index.jsp 重定向到主页
        return "test";
    }
}
